import { EntitySchema } from 'typeorm'

export const Tag = new EntitySchema({
  name: 'Tag',
  columns: {
    tag_id: {
      primary: true,
      type: 'int',
      generated: true
    },
    name: {
      type: 'varchar',
      length: 40,
      comment: '标签名称'
    },
    status: {
      type: 'int',
      default: 1,
      comment: '状态 0-禁用; 1-启用'
    },
    createTime: {
      type: 'datetime',
      comment: '创建时间',
      default: () => 'CURRENT_TIMESTAMP'
    },
    updateTime: {
      type: 'datetime',
      comment: '更新时间',
      updateDate: true
    }
  },
  relations: {
    articles: {
      type: 'many-to-many',
      target: 'Article',
      // 这个表不要使用 joinTable 否则会出现2个关联表的情况
      // joinTable: true,
      inverseSide: 'tags'
    }
  }
})
